package com.moonshot.controller;

import org.springframework.ai.moonshot.MoonshotChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @program: springboot3-demos
 * @description:
 * @author: Reagan Li
 * @create: 2024-07-11 17:26
 **/

@RestController
@RequestMapping("/ai/moonshot")
public class MoonshotController {

    @Autowired
    private MoonshotChatModel chatModel;

    /**
    * @Description:
    * @Param:
    * @return:
    * @Author: Reagan Li
    * @Date: 2024/7/11
    */
    @GetMapping("/chat")
    public ResponseEntity chat(@RequestParam("msg") String msg) {
        String call = chatModel.call(msg);
        return ResponseEntity.ok(call);
    }

    @GetMapping(value = "/chat/stream", produces = "text/html;charset=UTF-8")
    public Flux<String> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return chatModel.stream(message);
    }
}
